package com.kobeliu.manager.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.kobeliu.manager.LinkGroupManager;
import com.kobeliu.mapper.LinkGroupMapper;
import com.kobeliu.model.LinkGroupDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
public class LinkGroupManagerImpl implements LinkGroupManager {

    @Autowired
    private LinkGroupMapper linkGroupMapper;

    @Override
    public int add(LinkGroupDO linkGroupDO) {
        return linkGroupMapper.insert(linkGroupDO);
    }

    @Override
    public int del(Long groupId, Long accountNo) {

        //先根据groupId找到分组信息
        //再对照他们的accountId是否一致
        LinkGroupDO linkGroupDO = linkGroupMapper.selectById(groupId);
        if(linkGroupDO!=null){
            Long accountNo1 = linkGroupDO.getAccountNo();
            if(accountNo1.equals(accountNo)){
                return linkGroupMapper.deleteById(groupId);
            }
        }
        //删除失败 信息不一致
        return 0;
    }

    @Override
    public LinkGroupDO detail(Long groupId) {
        return linkGroupMapper.selectById(groupId);
    }

    @Override
    public List<LinkGroupDO> findAll(long accountNo) {
        return linkGroupMapper.selectList(new QueryWrapper<LinkGroupDO>().eq("account_no", accountNo));
    }

    @Override
    public int update(LinkGroupDO linkGroupDO) {
        return linkGroupMapper.update(linkGroupDO,new QueryWrapper<LinkGroupDO>().eq("id",linkGroupDO.getId()));
    }
}
